<template>
  <view class="content-analyse">
    <view class="header">
      <view class="top">
        <up-row>
          <up-col span="6">
            <view class="header-left"> {{ chartTitle }} </view>
          </up-col>
          <up-col span="6">
            <view
              class="header-right"
              v-if="
                props.type == 1 &&
                dataListSummaryDataModuleBMS.singleVoltageAverage > 0
              "
            >
              <text>
                {{ t("common.average") }} :
                {{ dataListSummaryDataModuleBMS.singleVoltageAverage }}
              </text>
            </view>
            <view
              class="header-right"
              v-if="
                props.type == 2 &&
                dataListSummaryDataModuleBMS.singleTemperatureAverage > 0
              "
            >
              <text>
                {{ t("common.average") }}:
                {{ dataListSummaryDataModuleBMS.singleTemperatureAverage }}
              </text>
            </view>
          </up-col>
        </up-row>
      </view>
    </view>
    <template v-if="Object.keys(chartOption).length !== 0">
      <EChartsWrapper :option="chartOption" />
    </template>
    <template v-else>
      <up-empty icon="/static/no-empty.png" :text="t('common.empty')">
      </up-empty>
    </template>
  </view>
</template>

<script setup>
import { ref, watch } from "vue";
import { useI18n } from "vue-i18n";
const { t } = useI18n();
const props = defineProps({
  chartTitle: {
    type: String,
    default: "",
  },
  voltageChartData: {
    type: Object,
    default: {},
  },
  dataListSummaryDataModuleBMS: {
    type: Object,
    default: {},
  },
  type: {
    type: Number,
    default: 1,
  },
});

// 定义图表配置项
const chartOption = ref(props.voltageChartData);
watch(
  () => props.voltageChartData,
  (val) => {
    chartOption.value = val;
  }
);
</script>

<style lang="scss" scoped>
.content-analyse {
  width: 100%;
  border-radius: 16rpx;
  background: #132034;
  padding: 32rpx 10rpx;
  box-sizing: border-box;
  .header {
    padding: 0rpx 39rpx;
    box-sizing: border-box;
    width: 100%;
    position: relative;
    .header-left {
      font-family: PingFangSC;
      font-size: 32rpx;
      font-weight: normal;
      color: #eeeeee;
    }
    .header-right {
      width: 100%;
      display: flex;
      justify-content: flex-end;
      align-items: center;
      text {
        font-family: Alibaba PuHuiTi 3;
        font-size: 24rpx;
        font-weight: normal;
        font-variation-settings: "opsz" auto;
        color: #dddddd;
        padding-left: 15rpx;
        box-sizing: border-box;
      }
    }
  }
  .header::after {
    content: "";
    position: absolute;
    left: -10rpx;
    top: 50%;
    transform: translateY(-50%);
    width: 8rpx;
    height: 32rpx;
    border-radius: 0px 8rpx 8rpx 0rpx;
    opacity: 1;
    background: #64b7f6;
  }
}
</style>
